package codeRandomThoughts.Test530二叉搜索树的最小绝对差;

import codeRandomThoughts.utils.TreeNode;

public class Solution2 {
    TreeNode pre = null;
    int minDiff = Integer.MAX_VALUE;

    public int getMinimumDifference(TreeNode root) {
        inorder(root);
        return minDiff;
    }

    public void inorder(TreeNode root) {
        if (root == null) {
            return;
        }
        //中序遍历
        //左
        inorder(root.left);

        //根
        if (pre!=null){
            int diff = Math.abs(root.val - pre.val);
            minDiff = Math.min(diff, minDiff);
        }
        pre = root;

        //右
        inorder(root.right);
    }
}
